import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';

export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'mainAccount',
    width: 120,
  },
  {
    title: '物品名称',
    dataIndex: 'goodsName',
    width: 180,
  },
  {
    title: '物品数量',
    dataIndex: 'goodsNum',
    width: 100,
  },
  {
    title: '支付价格',
    dataIndex: 'payAmount',
    width: 100,
  },
  {
    title: '物品类型',
    dataIndex: 'isVipCard',
    width: 100,
    align: 'center',
    customRender: ({ record }: Recordable) => {
      const isVipCardArray = [
        { label: '卡', value: 1 },
        { label: '非卡', value: 2 },
      ];
      const isVipCard: any = isVipCardArray.find(item => item.value == record.isVipCard);
      if (isVipCard) {
        return isVipCard.label;
      }
      return '';
    },
  },
  {
    title: '业绩状态',
    dataIndex: 'achievementState',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const achievementStateArray = [
        { label: '有效', value: 1 },
        { label: '无效', value: 2 },
      ];
      const achievementState: any = achievementStateArray.find(item => item.value == record.achievementState);
      if (achievementState) {
        return achievementState.label;
      }
      return '';
    },
  },
  {
    title: '所属销售',
    dataIndex: 'employeeName',
    width: 100,
  },
  {
    title: '地区',
    dataIndex: 'airportName',
    width: 100,
  },
  {
    title: '来源',
    dataIndex: 'sourceType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const sourceTypeArray = [
        { label: '订单', value: 1 },
        { label: '非订单', value: 2 },
      ];
      const sourceType: any = sourceTypeArray.find(item => item.value == record.sourceType);
      if (sourceType) {
        return sourceType.label;
      }
      return '';
    },
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'mainAccount',
    label: '会员账号',
    component: 'Input',
  },
  {
    field: 'airportId',
    label: '机场',
    component: 'ApiSelect',
    componentProps: {
      api: airportList,
      params: {},
      labelField: 'airportName',
      valueField: 'airportId',
      showSearch: true,
      immediate: true,
    },
  },
  {
    field: 'employeeId',
    label: '销售',
    component: 'ApiSelect',
    componentProps: {
      api: employeeList,
      params: {},
      labelField: 'employeeName',
      valueField: 'employeeId',
      immediate: true,
    },
  },
  {
    field: 'achievementState',
    label: '业绩状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '有效', value: 1 },
        { label: '失效', value: 2 },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '业绩Id',
    field: 'achievementId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '物品名称',
    field: 'goodsName',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '物品数量',
    field: 'goodsNum',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '所属地区',
    field: 'airportId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      showSearch: true,
      immediate: true,
    },
  },
  {
    label: '所属销售',
    field: 'employeeId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: employeeList,
      labelField: 'employeeName',
      valueField: 'employeeId',
      showSearch: true,
      immediate: true,
    },
  },
  {
    label: '业绩状态',
    field: 'achievementState',
    component: 'Select',
    required: false,
    componentProps: {
      options: [
        { label: '有效', value: 1 },
        { label: '失效', value: 2 },
      ],
    },
  },
];
